//
//  HotViewController.m
//  SnacksOfChina
//
//  Created by qianfeng on 15/9/14.
//  Copyright (c) 2015年 AD Wang. All rights reserved.
//

#import "HotViewController.h"
#import "HotModel.h"
#import "HotCell.h"
#import "JHRefresh.h"

@interface HotViewController ()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (nonatomic, strong)UICollectionView * collectionView;
@property (nonatomic, strong)NSMutableArray * dataArr;
@property (nonatomic, strong)AFHTTPRequestOperationManager * manager;
@property (nonatomic)NSInteger currentPage;

@property (nonatomic)BOOL isRefreshing;
@property (nonatomic)BOOL isLoadMore;

#define kCellId @"HotCell"
#define kFootterId @"CollectionFootViewId"

@end

@implementation HotViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createCollectionView];
    [self createAFNetwork];
    [self loadHotData];
    
    self.navigationItem.title = @"热门饮食专题";
    self.navigationController.navigationBar.backgroundColor = [UIColor clearColor];
    _dataArr = [[NSMutableArray alloc]init];
    
}

#pragma mark - 解析数据
- (void)loadHotData
{
    self.isRefreshing = NO;
    self.isLoadMore = NO;
    _currentPage = 1;
    NSString * url = nil;
    url = [NSString stringWithFormat:]
    
}

#pragma mark - UICollectionView
- (void)createCollectionView
{
    UICollectionViewFlowLayout * layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(kScreenSize.width, kScreenSize.height - 64 - 49);
    layout.footerReferenceSize = CGSizeMake(50, 50);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, kScreenSize.width, kScreenSize.height - 64 - 49) collectionViewLayout:layout];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    //按页滚动
    self.collectionView.pagingEnabled = YES;
    
    
}

#pragma mark - UICollectionViewDelegate&UICollectionViewDataSource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.dataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{   //复用队列获取cell
    HotCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCellId forIndexPath:indexPath];
    //获取model 填充cell
    HotModel * model = self.dataArr[indexPath.row];
    [cell showDataWithModel:model];
    
    //如果是第一个，那么下载完了之后应当立即显示
//    if (indexPath.row == 0) {
//        [self.data];
//    }
    return cell;
}

#pragma mark - 选中cell
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark - 尾部加载更多
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
    if ([kind isEqualToString:UICollectionElementKindSectionFooter]) {
        UICollectionReusableView * footView = [self.collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:kFootterId forIndexPath:indexPath];
        if ([self.dataArr count] == 0) {
            footView.backgroundColor = [UIColor clearColor];
        }else
        {
            UILabel * label = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 50, kScreenSize.height - 64 - 49)];
            label.numberOfLines = 0;
        }
        
    }
    return 0;
}

- (void)createAFNetwork
{
    
}



@end






